<%
layout("layout.html"){
%>
<div class="page__bd" style="margin-top: 100px;">
    <div class="weui-cells__title">修改密码</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">密码</label>
            </div>
            <div class="weui-cell__bd">
                <input id="passwordInput" type="password" class="weui-input" placeholder="请输入密码" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">确认密码</label>
            </div>
            <div class="weui-cell__bd">
                <input id="confirmPasswordInput" type="password" class="weui-input" placeholder="请输入密码" />
            </div>
        </div>
        <div class="weui-btn-area" style="margin-top: 100px;">
            <a id="submitButton" class="weui-btn weui-btn_warn">修改</a>
        </div>
    </div>
</div>
<script src="${ctxPath}/js/md5.min.js"></script>
<script src="${ctxPath}/js/net.js"></script>
<script>
    $('#submitButton').click(function () {
        var password = $('#passwordInput').val();
        var confirmPassword = $('#confirmPasswordInput').val();
        if (password == null) {
            alert('密码为空');
        }
        if (password != confirmPassword) {
            alert('两次密码不一致');
            return;
        }
        password = md5(password);
        net().url("${ctxPath}/api/user/password").data({password: password})
            .success(function (response) {
                if (response.code == 0) {
                    showToast();
                    window.history.back();
                } else {
                    alert(response.message);
                }
            })
            .error(function(err) {
                alert('网络错误');
            }).put();
    });
</script>
<% } %>